package org.ruwang.chinamobileai.embeddings;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class RuleDataEmbedding {

    /**
     * 向量存储服务，用于持久化文档向量
     */
    private final VectorStore vectorStore;

    /**
     *数据文件资源路径
     */
    @Value("classpath:rule-data.json")
    private Resource resource;


    @PostConstruct
    public void init() throws Exception{
        //创建json读取器并加载文件内容
        JsonReader jsonReader = new JsonReader(resource, "type", "condition", "description");
        List<Document> documents = jsonReader.get();

        //将处理后的文档向量化并存入向量存储
        vectorStore.add(documents);
    }

}
